﻿Imports AugmentLib.Database
Imports System.Configuration.ConfigurationManager
Imports AugmentLib.RDLC

Partial Class rptListing
    Inherits System.Web.UI.Page

#Region " Properties "

    Public Property CurrentPage() As Integer
        Get
            'Looks for the current page in ViewState
            Dim objPage As Object = ViewState("_CurrentPage")
            If objPage Is Nothing Then
                Return 0
            Else
                'default to showing the first page
                Return CInt(objPage)
            End If
        End Get
        Set(ByVal value As Integer)
            ViewState("_CurrentPage") = value
        End Set
    End Property

    Public Property PageSize() As Integer
        Get
            'Looks for the current page in ViewState
            Dim objPageSize As Object = ViewState("_PageSize")
            If objPageSize Is Nothing Then
                Return 25
            Else
                'default to showing the first page
                Return CInt(objPageSize)
            End If
        End Get
        Set(ByVal value As Integer)
            ViewState("_PageSize") = value
        End Set
    End Property

#End Region

#Region " Paging and Page Size "

    Protected Sub lnkHead10Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead10Item.Click
        PageSize = 10
       
        LoadRptListing()
    End Sub

    Protected Sub lnkHead25Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead25Item.Click
        PageSize = 25
        LoadRptListing()
    End Sub

    Protected Sub lnkHead100Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead100Item.Click
        PageSize = 100
        LoadRptListing()
    End Sub

    Protected Sub lnkHead150Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead150Item.Click
        PageSize = 150
        LoadRptListing()
    End Sub

    Protected Sub lnkFoot10Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot10Item.Click
        PageSize = 10
        LoadRptListing()
    End Sub

    Protected Sub lnkFoot25Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot25Item.Click
        PageSize = 25
        LoadRptListing()
    End Sub

    Protected Sub lnkFoot100Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot100Item.Click
        PageSize = 100
        LoadRptListing()
    End Sub

    Protected Sub lnkFoot150Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot150Item.Click
        PageSize = 150
        LoadRptListing()
    End Sub

    Protected Sub btnMoveFirst_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMoveFirst.Click
        CurrentPage = 0
        txtPageNo.Text = CurrentPage + 1
        LoadRptListing()
    End Sub

    Protected Sub btnPrevious_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        If CurrentPage > 0 Then
            CurrentPage = CurrentPage - 1
            txtPageNo.Text = CurrentPage + 1
            LoadRptListing()
        End If
    End Sub

    Protected Sub btnGo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGo.Click
        If CInt(txtPageNo.Text < 1) Then
            txtPageNo.Text = 1
        End If

        If CInt(txtPageNo.Text > CInt(lblMaxPageCount.Text)) Then
            txtPageNo.Text = CInt(lblMaxPageCount.Text) + 1
        End If

        CurrentPage = CInt(txtPageNo.Text) - 1
        LoadRptListing()

    End Sub

    Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click
        If CurrentPage < CInt(lblMaxPageCount.Text) Then
            CurrentPage = CurrentPage + 1
            txtPageNo.Text = CurrentPage + 1
             LoadRptListing()
        End If
    End Sub

    Protected Sub btnMoveLast_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMoveLast.Click
        CurrentPage = CInt(lblMaxPageCount.Text)
        txtPageNo.Text = CurrentPage + 1
        LoadRptListing()
    End Sub

#End Region

    Private Function LoadListing() As Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        Dim strWhere As String
        Dim strSelectDate As String
        Dim strUNIONALL As String
        Dim strWho As String
        strUNIONALL = ""
        strWho = ""

        Dim dtFromDate As DateTime
        Dim dtToDate As DateTime
        'to add in filtering for report - fromDate, toDate, Type(Created;Updated)
        If txtFromDate.Text <> "" And txtToDate.Text <> "" Then
            dtFromDate = Date.ParseExact(txtFromDate.Text, "dd-MMM-yyyy", Nothing)
            dtToDate = Date.ParseExact(txtToDate.Text, "dd-MMM-yyyy", Nothing)
            If dtFromDate > dtToDate Then
                lblMsgError.Text = "Date To cannot be earlier than Date From!"
                divError.Visible = True
                Return Nothing
                Exit Function
            Else
                strSelectDate = "CASE ISNULL(p.UpdateDate,'') WHEN '' THEN p.CreateDate ELSE p.UpdateDate END as 'Date', " & _
                                "CASE ISNULL(p.UpdateDate,'') WHEN '' THEN 'Created' ELSE 'Updated' END as 'Type', "    'Edit by Tan Chin Teong 20120429


                If ddlStaffName.SelectedValue = "" Then '--All
                    strWhere = "WHERE "
                Else
                    If ddlStatus.SelectedValue = "2" Then   '--All
                        strWhere = "WHERE (p.SListerId=@StaffId) AND "
                        strWho = " AND (p.RListerId=@StaffId) "
                    ElseIf ddlStatus.SelectedValue = "0" Then '--SALE
                        strWhere = "WHERE (p.SListerId=@StaffId) AND "
                    Else    '--RENT
                        strWhere = "WHERE (p.RListerId=@StaffId) AND "
                    End If

                    objDB.AddParameter("StaffId", Data.SqlDbType.UniqueIdentifier, New Guid(ddlStaffName.SelectedValue))
                End If

                'If ddlType.SelectedValue = "2" Then '--All
                '    strWhere = strWhere & "(p.CreateDate BETWEEN @DateFrom and @DateTo AND p.UpdateDate IS NULL) " & _
                '            "OR p.UpdateDate BETWEEN @DateFrom and @DateTo " & lblHidSortType.Text
                'ElseIf ddlType.SelectedValue = "0" Then '--Created
                '    strWhere = strWhere & "p.CreateDate BETWEEN @DateFrom and @DateTo " & lblHidSortType.Text    'Edit by Tan Chin Teong 20120429
                '    strSelectDate = "p.CreateDate as 'Date', " & _
                '                    "'Created' as 'Type', "
                'ElseIf ddlType.SelectedValue = "1" Then '--Updated
                '    strWhere = strWhere & "p.UpdateDate BETWEEN @DateFrom and @DateTo " & lblHidSortType.Text
                'Else : strWhere = ""
                'End If

                'edited by tanchinteong @20121125
                'separate out RENT & SALE
                If ddlStatus.SelectedValue = "2" Then '--All
                    'UNION ALL of Both
                    strWhere = strWhere & "p.SCreateDate BETWEEN @DateFrom and @DateTo "    'Edit by Tan Chin Teong 20120429
                    strSelectDate = "p.SCreateDate as 'Date', " & _
                                    "'Sales' as 'Type',"

                    strUNIONALL = " UNION ALL SELECT CASE WHEN ISNULL(S.Initial, '') <> '' AND ISNULL(R.Initial, '') <> '' THEN S.Initial + ', ' + R.Initial " & _
                                    "WHEN ISNULL(S.Initial, '') = '' AND ISNULL(R.Initial, '') <> '' THEN R.Initial " & _
                                    "WHEN ISNULL(S.Initial, '') <> '' AND ISNULL(R.Initial, '') = '' THEN S.Initial " & _
                                    "ELSE '' END as 'Initial', " & _
                                    "p.SCreateDate as 'Date', " & _
                                    "'Rent' as 'Type'," & _
                                    "p.UnitNumber as 'PNO', ro.road, pr.project, lo.location, st.State, " & _
                                    "CASE p.ListType WHEN '3' THEN 'SALE, RENT' WHEN '2' THEN 'RENT' WHEN '1' THEN 'SALE' ELSE '' END as 'ListType', " & _
                                    "CASE SRYes WHEN '1' THEN 'SR ' ELSE '' END + " & _
                                    "CASE SCYes WHEN '1' THEN 'SC ' ELSE '' END + " & _
                                    "CASE SLYes WHEN '1' THEN 'SL ' ELSE '' END + " & _
                                    "CASE SIYes WHEN '1' THEN 'SI ' ELSe '' END + " & _
                                    "CASE RRYes WHEN '1' THEN 'RR ' ELSE '' END + " & _
                                    "CASE RCYes WHEN '1' THEN 'RC ' ELSE '' END + " & _
                                    "CASE RLYes WHEN '1' THEN 'RL ' ELSE '' END + " & _
                                    "CASE RIYes WHEN '1' THEN 'RI ' ELSe '' END as 'Category' " & _
                                    "FROM aw_Property p LEFT JOIN aw_Staff S on p.SListerId = S.StaffId " & _
                                    "LEFT JOIN aw_Staff R on p.RListerId = R.StaffId " & _
                                    "LEFT JOIN aw_Road ro on ro.RoadId = p.RoadId " & _
                                    "LEFT JOIN aw_Location lo on lo.LocationId = ro.LocationId " & _
                                    "LEFT JOIN aw_State st on st.StateId = lo.StateId " & _
                                    "LEFT JOIN aw_Project pr on pr.ProjectId = p.ProjectId where p.RCreateDate BETWEEN @DateFrom and @DateTo " & strWho & lblHidSortType.Text

                ElseIf ddlStatus.SelectedValue = "0" Then '--SALE
                    'SCreateDate
                    strWhere = strWhere & "p.SCreateDate BETWEEN @DateFrom and @DateTo " & lblHidSortType.Text    'Edit by Tan Chin Teong 20120429
                    strSelectDate = "p.SCreateDate as 'Date', " & _
                                    "'Sales' as 'Type',"

                ElseIf ddlStatus.SelectedValue = "1" Then '--RENT
                    'RCreateDate
                    strWhere = strWhere & "p.RCreateDate BETWEEN @DateFrom and @DateTo " & lblHidSortType.Text    'Edit by Tan Chin Teong 20120429
                    strSelectDate = "p.RCreateDate as 'Date', " & _
                                    "'Rent' as 'Type',"
                Else
                End If

                objDB.AddParameter("DateFrom", Data.SqlDbType.DateTime, dtFromDate)
                objDB.AddParameter("DateTo", Data.SqlDbType.DateTime, dtToDate.AddDays(1))
                objDB.OpenConnection()
                objDB.dbVariable.SQLString = "SELECT CASE WHEN ISNULL(S.Initial, '') <> '' AND ISNULL(R.Initial, '') <> '' THEN S.Initial + ', ' + R.Initial " & _
                                    "WHEN ISNULL(S.Initial, '') = '' AND ISNULL(R.Initial, '') <> '' THEN R.Initial " & _
                                    "WHEN ISNULL(S.Initial, '') <> '' AND ISNULL(R.Initial, '') = '' THEN S.Initial " & _
                                    "ELSE '' END as 'Initial', " & _
                                    strSelectDate & _
                                    "p.UnitNumber as 'PNO', ro.road, pr.project, lo.location, st.State, " & _
                                    "CASE p.ListType WHEN '3' THEN 'SALE, RENT' WHEN '2' THEN 'RENT' WHEN '1' THEN 'SALE' ELSE '' END as 'ListType', " & _
                                    "CASE SRYes WHEN '1' THEN 'SR ' ELSE '' END + " & _
                                    "CASE SCYes WHEN '1' THEN 'SC ' ELSE '' END + " & _
                                    "CASE SLYes WHEN '1' THEN 'SL ' ELSE '' END + " & _
                                    "CASE SIYes WHEN '1' THEN 'SI ' ELSe '' END + " & _
                                    "CASE RRYes WHEN '1' THEN 'RR ' ELSE '' END + " & _
                                    "CASE RCYes WHEN '1' THEN 'RC ' ELSE '' END + " & _
                                    "CASE RLYes WHEN '1' THEN 'RL ' ELSE '' END + " & _
                                    "CASE RIYes WHEN '1' THEN 'RI ' ELSe '' END as 'Category' " & _
                                    "FROM aw_Property p LEFT JOIN aw_Staff S on p.SListerId = S.StaffId " & _
                                    "LEFT JOIN aw_Staff R on p.RListerId = R.StaffId " & _
                                    "LEFT JOIN aw_Road ro on ro.RoadId = p.RoadId " & _
                                    "LEFT JOIN aw_Location lo on lo.LocationId = ro.LocationId " & _
                                    "LEFT JOIN aw_State st on st.StateId = lo.StateId " & _
                                    "LEFT JOIN aw_Project pr on pr.ProjectId = p.ProjectId " & strWhere & strUNIONALL
                objDB.FillData(TempDT, "AW_Property", Database.SQLCommandType.NormalString)
                objDB.CloseConnection()
                'Creating a Paged Datasouce
                Return TempDT
            End If
        Else
            lblMsgError.Text = "Please select a date range!"
            divError.Visible = True
            Return Nothing
            Exit Function
        End If
    End Function

    Private Sub LoadRptListing()

        Dim TempDT As New Data.DataTable

        TempDT = LoadListing()

        If TempDT IsNot Nothing Then
            Dim objPaged As New PagedDataSource
            objPaged.DataSource = TempDT.DefaultView
            objPaged.AllowPaging = True
            objPaged.PageSize = PageSize
            objPaged.CurrentPageIndex = CurrentPage

            lblHeadNoOfItem.Text = TempDT.Rows.Count
            lblFootNoOfItem.Text = TempDT.Rows.Count

            repListing.DataSource = objPaged
            repListing.DataBind()

            lblMaxPageCount.Text = objPaged.PageCount - 1
            lblTotalPage.Text = " of " & objPaged.PageCount
        End If
    End Sub

    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        LoadRptListing()
    End Sub

    Protected Sub btnResetSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnResetSearch.Click
        ClearAllFields()
    End Sub

    Private Sub ClearAllFields()
        txtFromDate.Text = String.Empty
        txtToDate.Text = String.Empty
        ddlStatus.SelectedIndex = -1
    End Sub

    Private Function SortType(ByVal strSortType As String) As String
        Dim strSort As String
        If Right(strSortType, 1) = "▼" Then
            strSort = "ASC"
        Else
            strSort = "DESC"
        End If
        Return strSort
    End Function

    Protected Sub lnkDate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkDate.Click
        If lnkDate.Text = "Date▼" Then
            lnkDate.Text = "Date▲"
        Else
            lnkDate.Text = "Date▼"
        End If

        lblHidSortType.Text = " ORDER BY Date " & SortType(lnkDate.Text) & ", Initial " & SortType(lnkInitial.Text) & _
        ", PNO " & SortType(lnkPNO.Text) & ", Road " & SortType(lnkRoad.Text) & ", Project " & SortType(lnkProject.Text) & _
        ", Location " & SortType(lnkLocation.Text) & ", State " & SortType(lnkState.Text) & ", ListType " & SortType(lnkListType.Text) & _
        ", Category " & SortType(lnkCategory.Text) & ", Type " & SortType(lnkType.Text)
        LoadRptListing()
    End Sub

    Protected Sub lnkInitial_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkInitial.Click
        If lnkInitial.Text = "Initial▼" Then
            lnkInitial.Text = "Initial▲"
        Else
            lnkInitial.Text = "Initial▼"
        End If

        lblHidSortType.Text = " ORDER BY Initial " & SortType(lnkInitial.Text) & ", Date " & SortType(lnkDate.Text) & _
        ", PNO " & SortType(lnkPNO.Text) & ", Road " & SortType(lnkRoad.Text) & ", Project " & SortType(lnkProject.Text) & _
        ", Location " & SortType(lnkLocation.Text) & ", State " & SortType(lnkState.Text) & ", ListType " & SortType(lnkListType.Text) & _
        ", Category " & SortType(lnkCategory.Text) & ", Type " & SortType(lnkType.Text)
        LoadRptListing()
    End Sub

    Protected Sub lnkPNO_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkPNO.Click
        If lnkPNO.Text = "PNO▼" Then
            lnkPNO.Text = "PNO▲"
        Else
            lnkPNO.Text = "PNO▼"
        End If

        lblHidSortType.Text = " ORDER BY PNO " & SortType(lnkPNO.Text) & ", Date " & SortType(lnkDate.Text) & _
        ", Initial " & SortType(lnkInitial.Text) & ", Road " & SortType(lnkRoad.Text) & ", Project " & SortType(lnkProject.Text) & _
        ", Location " & SortType(lnkLocation.Text) & ", State " & SortType(lnkState.Text) & ", ListType " & SortType(lnkListType.Text) & _
        ", Category " & SortType(lnkCategory.Text) & ", Type " & SortType(lnkType.Text)
        LoadRptListing()
    End Sub

    Protected Sub lnkRoad_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkRoad.Click
        If lnkRoad.Text = "Road Name▼" Then
            lnkRoad.Text = "Road Name▲"
        Else
            lnkRoad.Text = "Road Name▼"
        End If

        lblHidSortType.Text = " ORDER BY Road " & SortType(lnkRoad.Text) & ", Date " & SortType(lnkDate.Text) & _
        ", Initial " & SortType(lnkInitial.Text) & ", PNO " & SortType(lnkPNO.Text) & ", Project " & SortType(lnkProject.Text) & _
        ", Location " & SortType(lnkLocation.Text) & ", State " & SortType(lnkState.Text) & ", ListType " & SortType(lnkListType.Text) & _
        ", Category " & SortType(lnkCategory.Text) & ", Type " & SortType(lnkType.Text)
        LoadRptListing()
    End Sub

    Protected Sub lnkProject_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkProject.Click
        If lnkProject.Text = "Project Name▼" Then
            lnkProject.Text = "Project Name▲"
        Else
            lnkProject.Text = "Project Name▼"
        End If

        lblHidSortType.Text = " ORDER BY Project " & SortType(lnkProject.Text) & ", Date " & SortType(lnkDate.Text) & _
        ", Initial " & SortType(lnkInitial.Text) & ", PNO " & SortType(lnkPNO.Text) & ", Road " & SortType(lnkRoad.Text) & _
        ", Location " & SortType(lnkLocation.Text) & ", State " & SortType(lnkState.Text) & ", ListType " & SortType(lnkListType.Text) & _
        ", Category " & SortType(lnkCategory.Text) & ", Type " & SortType(lnkType.Text)
        LoadRptListing()
    End Sub

    Protected Sub lnkLocation_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkLocation.Click
        If lnkLocation.Text = "Location▼" Then
            lnkLocation.Text = "Location▲"
        Else
            lnkLocation.Text = "Location▼"
        End If

        lblHidSortType.Text = " ORDER BY Location " & SortType(lnkLocation.Text) & ", Date " & SortType(lnkDate.Text) & _
        ", Initial " & SortType(lnkInitial.Text) & ", PNO " & SortType(lnkPNO.Text) & ", Road " & SortType(lnkRoad.Text) & _
        ", Project " & SortType(lnkProject.Text) & ", State " & SortType(lnkState.Text) & ", ListType " & SortType(lnkListType.Text) & _
        ", Category " & SortType(lnkCategory.Text) & ", Type " & SortType(lnkType.Text)
        LoadRptListing()
    End Sub

    Protected Sub lnkState_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkState.Click
        If lnkState.Text = "State▼" Then
            lnkState.Text = "State▲"
        Else
            lnkState.Text = "State▼"
        End If

        lblHidSortType.Text = " ORDER BY State " & SortType(lnkState.Text) & ", Date " & SortType(lnkDate.Text) & _
        ", Initial " & SortType(lnkInitial.Text) & ", PNO " & SortType(lnkPNO.Text) & ", Road " & SortType(lnkRoad.Text) & _
        ", Project " & SortType(lnkProject.Text) & ", Location " & SortType(lnkLocation.Text) & ", ListType " & SortType(lnkListType.Text) & _
        ", Category " & SortType(lnkCategory.Text) & ", Type " & SortType(lnkType.Text)
        LoadRptListing()
    End Sub

    Protected Sub lnkListType_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkListType.Click
        If lnkListType.Text = "Transaction Type▼" Then
            lnkListType.Text = "Transaction Type▲"
        Else
            lnkListType.Text = "Transaction Type▼"
        End If

        lblHidSortType.Text = " ORDER BY ListType " & SortType(lnkListType.Text) & ", Date " & SortType(lnkDate.Text) & _
        ", Initial " & SortType(lnkInitial.Text) & ", PNO " & SortType(lnkPNO.Text) & ", Road " & SortType(lnkRoad.Text) & _
        ", Project " & SortType(lnkProject.Text) & ", Location " & SortType(lnkLocation.Text) & ", State " & SortType(lnkState.Text) & _
        ", Category " & SortType(lnkCategory.Text) & ", Type " & SortType(lnkType.Text)
        LoadRptListing()
    End Sub

    Protected Sub lnkCategory_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkCategory.Click
        If lnkCategory.Text = "Category▼" Then
            lnkCategory.Text = "Category▲"
        Else
            lnkCategory.Text = "Category▼"
        End If

        lblHidSortType.Text = " ORDER BY Category " & SortType(lnkCategory.Text) & ", Date " & SortType(lnkDate.Text) & _
        ", Initial " & SortType(lnkInitial.Text) & ", PNO " & SortType(lnkPNO.Text) & ", Road " & SortType(lnkRoad.Text) & _
        ", Project " & SortType(lnkProject.Text) & ", Location " & SortType(lnkLocation.Text) & ", State " & SortType(lnkState.Text) & _
        ", ListType " & SortType(lnkListType.Text) & ", Type " & SortType(lnkType.Text)
        LoadRptListing()
    End Sub

    Protected Sub lnkType_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkType.Click
        If lnkType.Text = "Type▼" Then
            lnkType.Text = "Type▲"
        Else
            lnkType.Text = "Type▼"
        End If

        lblHidSortType.Text = " ORDER BY Type " & SortType(lnkType.Text) & ", Date " & SortType(lnkDate.Text) & _
        ", Initial " & SortType(lnkInitial.Text) & ", PNO " & SortType(lnkPNO.Text) & ", Road " & SortType(lnkRoad.Text) & _
        ", Project " & SortType(lnkProject.Text) & ", Location " & SortType(lnkLocation.Text) & ", State " & SortType(lnkState.Text) & _
        ", ListType " & SortType(lnkListType.Text) & ", Category " & SortType(lnkCategory.Text)
        LoadRptListing()
    End Sub

    Protected Sub imgGenerate_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgGenerate.Click
        Dim TempDT As New Data.DataTable

        TempDT = LoadListing()

        If TempDT IsNot Nothing Then
            Dim objRDLC As New RDLC("report/rptListing.rdlc", "ListingReport")
            TempDT.TableName = "dsListing_AW_Property"
            objRDLC.AddDatabase(TempDT)
            If ddlStatus.SelectedValue = 0 Then
                objRDLC.AddParameter("ReportType", "Sale")
            ElseIf ddlStatus.SelectedValue = 1 Then
                objRDLC.AddParameter("ReportType", "Rent")
            ElseIf ddlStatus.SelectedValue = 2 Then
                objRDLC.AddParameter("ReportType", "Sale & Rent")
            End If
            objRDLC.ExportReport(RDLC.ExportTypeFormat.PDF, HttpContext.Current)
        End If

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("StaffId") Is Nothing Then
            Response.Redirect("Default.aspx")
        Else
            lblStaffUID.Text = Session("StaffId").ToString
        End If

        If Not Page.IsPostBack Then
            GetddlListBy()
        End If

    End Sub

    'Edit by Tan Chin Teong 20120712
    Private Sub GetddlListBy()
        Dim TempDT As New Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT StaffId,Name FROM AW_Staff WHERE StatusDelete = 0 ORDER BY Name"
        objDB.FillData(TempDT, "AW_Staff", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()

        With ddlStaffName
            .DataSource = TempDT
            .DataTextField = "Name"
            .DataValueField = "StaffId"
            .DataBind()
            .Items.Insert(0, "ANY")
            .Items(0).Value = ""
        End With
    End Sub

End Class


